//地图定位
function setmap1(ss) {
	var map;
	var watchId;
	var watchIdCount = 1;
	//alert("请求位置")

	if(navigator.geolocation) {
		//alert(JSON.stringify(navigator.geolocation))
		watchId = navigator.geolocation.getCurrentPosition(showPosition, showError, {
			enableHighAcuracy: true,
			timeout: 5000,
			maximumAge: 100000
		});
		//设置定位缓存
		return watchId;
	} else {

		return false;
	}
}

function showPosition(position) {

	//  positioning.latitude = position.coords.latitude;//纬
	//  positioning.longitude = position.coords.longitude;//经
	//  positioning.accuracy = position.coords.accuracy;//精确度

	setCookie("gps", position.coords.latitude + "," + position.coords.longitude, 1)

	try {
		setindexpage.start.success1();
	} catch(e) {
		// handle the exception
	}
	//?latlng=39.8998854032,116.6101441362&key=
	return position;
}

function showError(error) {
	var t_h = "错误信息：<br>";
	switch(error.code) {
		case error.TIMEOUT:
			t_h += "请求超时。如果在中国地区，谷歌 Chrome 或基于此内核的浏览器可能无法定位，您可以尝试其它浏览器如 IE / Edge。<br />A timeout occured! Please try again!";
			break;
		case error.POSITION_UNAVAILABLE:
			t_h += "抱谦，无法检测位置。如果设备有GPS，需在室外且GPS正常启动。<br />We can't detect your location. Sorry!";
			break;
		case error.PERMISSION_DENIED:
			t_h += "请充许浏览器访问地理位置请求。<br />Please allow geolocation access for this to work.";
			break;
		case error.UNKNOWN_ERROR:
			t_h += "发生未知错误<br />An unknown error occured!";
			break;
		default:
			t_h += "发生未知错误<br />An unknown error occured!";
			break;
	}
	console.log(t_h)
	// console.log(setindexpage.start.setintergps)
	//错误回调
	try {
		setindexpage.start.error1();
	} catch(e) {
		// handle the exception
	}

	//  $.modal({
	//      title: "测试",
	//      text: t_h,
	//      buttons: [
	//        { text: "<span class='aaa'>ok</span>", onClick: function () {
	//
	//          }}
	//      ]
	//  });

	return false;
	//失败
}
//计算两点间距离
function getGreatCircleDistance(lat1, lng1, lat2, lng2) {
	var EARTH_RADIUS = 6378137.0; //单位M
	var radLat1 = getRad(lat1);
	var radLat2 = getRad(lat2);
	var a = radLat1 - radLat2;
	var b = getRad(lng1) - getRad(lng2);
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * EARTH_RADIUS;
	s = Math.round(s * 10000) / 10000.0;
	console.log(s)
	return s;
}
//getGreatCircleDistance(1.5158274568447936,103.6682628840208,1.515804097509356,103.6682012627918)
//getGreatCircleDistance(1.5158274568447936,103.6682628840208,1.5157781,103.6681195)
//getGreatCircleDistance(1.5158274568447936,103.6682628840208,1.5157847,103.6680992)
function getRad(d) {
	var PI = Math.PI;
	return d * PI / 180.0;
}